define(['jquery','api','user','util','qrcode'],function($,api,user,util){
	var vm,
	   controller = {
	   init:function(id){
	   	   if(!user.checkLogin())return;
	   	   api.footerShow(0);//隐藏底部导航
		   api.setTitle(L('html_title_user_card'));
		   	api.headerShow(1);
			api.headerTitle(L('html_title_user_card'));
		   
		   this.render();
	   },
	   render:function(){
	   	   var that=this;
	   	   $('#common').html('<div id="userCard"></div>');
	       require(['text!pages/user/card.html','Vue'],function(tpl,Vue){
	            vm=new Vue({
	               el:'#userCard',
	               data:{
	               	  show:true,
	               	  qrshow:false,
	               	  user:user.getData(),
	               	  imgSrc:false,
	               	  links:[{url:'#/user/customer',text:'客户信息'},{url:'#/user/commission',text:'佣金分成'}]
	               },
	               methods:{
	                  
	               },
	               template:tpl
	            });
	            
	            // 没有必要参数就不显示二维码
	            if(parseInt(vm.user.uid) && parseInt(vm.user.pid)){
	                that.createQr(vm.user.uid,vm.user.pid);
	                vm.qrshow = true;
	            }
	       })
	   },
	   createQr:function(uid,pid){
		  var str='http://'+location.host+'/#/agent/'+uid+'/'+pid,
		      ct=$('#qrCt');
		  
		  ct.qrcode({
		       render:'image',
		       size:200,
		       text:str
		  });
	      setTimeout(function(){
	           vm.imgSrc=ct.find('img').attr('src');
	      },0);
	   	},
	   onRouteChange:function(){
	       if(vm)vm.show=false;
	   }
	};
    return controller;
})